package com.weikuang.fareast.activityNew;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.jzxiang.pickerview.TimePickerDialog;
import com.jzxiang.pickerview.data.Type;
import com.jzxiang.pickerview.listener.OnDateSetListener;
import com.licheedev.myutils.LogPlus;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.weikuang.fareast.R;
import com.weikuang.fareast.activity.BaseActivity;
import com.weikuang.fareast.activity.HotelActivity;
import com.weikuang.fareast.activity.NotActivity;
import com.weikuang.fareast.activity.StatisticsActivity;
import com.weikuang.fareast.adapter.OutGoodsAdapter;
import com.weikuang.fareast.bean.AddGoodsBean;
import com.weikuang.fareast.bean.AddOrderOutBean;
import com.weikuang.fareast.bean.BranchCodeList;
import com.weikuang.fareast.bean.BranchListByCustomer;
import com.weikuang.fareast.bean.ChangOrderBean;
import com.weikuang.fareast.bean.CustomerBean;
import com.weikuang.fareast.bean.DriverListBean;
import com.weikuang.fareast.bean.HotelBean;
import com.weikuang.fareast.bean.OrderBean;
import com.weikuang.fareast.bean.OrderDetailListBean;
import com.weikuang.fareast.bean.OrderListBean;
import com.weikuang.fareast.bean.OrderNoInfoBean;
import com.weikuang.fareast.bean.OutGoodsBean;
import com.weikuang.fareast.bean.PrintOrderOutBean;
import com.weikuang.fareast.network.KillerApi;
import com.weikuang.fareast.network.MainApi;
import com.weikuang.fareast.network.MyObserve;
import com.weikuang.fareast.utils.UserHelper;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.dlc.commonlibrary.ui.widget.CommonItemView;
import cn.dlc.commonlibrary.ui.widget.TitleBar;
import cn.dlc.commonlibrary.ui.widget.popup.CommonPopupList;
import cn.dlc.commonlibrary.utils.TimeFormats;
import cn.dlc.commonlibrary.utils.ToastUtil;
import cn.dlc.commonlibrary.utils.rv_tool.RecyclerViewUtil;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

//出货
public class OutGoodsHkActivity extends BaseActivity  implements OnDateSetListener {


    @BindView(R.id.mTitleBar)
    TitleBar mTitleBar;
    @BindView(R.id.tv_customer)
    TextView tvCustomer;
    @BindView(R.id.drop_customer)
    FrameLayout dropCustomer;
    @BindView(R.id.item_customer)
    CommonItemView itemCustomer;
    @BindView(R.id.tv_group)
    TextView tvGroup;
    @BindView(R.id.drop_group)
    FrameLayout dropGroup;
    @BindView(R.id.item_group)
    CommonItemView itemGroup;

    @BindView(R.id.tv_order)
    TextView tvOrder;
    @BindView(R.id.drop_order)
    FrameLayout dropOrder;
    @BindView(R.id.item_order)
    CommonItemView itemOrder;

    @BindView(R.id.tv_driver)
    TextView tvDriver;   //司机
    @BindView(R.id.drop_driver)
    FrameLayout dropDriver;
    @BindView(R.id.item_driver)
    CommonItemView itemDriver;

    @BindView(R.id.btn_goods)
    Button btn_goods;
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;

    @BindView(R.id.start_time)
    CommonItemView startTime;
    @BindView(R.id.end_time)
    CommonItemView endTime;

    @BindView(R.id.tv_delivery_time)
    TextView tvDeliveryTime;   //收货时间
    @BindView(R.id.drop_delivery_time)
    FrameLayout dropDeliveryTime;
    @BindView(R.id.item_delivery_time)
    CommonItemView itemDeliveryTime;

    @BindView(R.id.tv_number)
    TextView tvNumber;   //分行编号
    @BindView(R.id.drop_number)
    FrameLayout dropNumber;
    @BindView(R.id.item_number)
    CommonItemView itemNumber;

    @BindView(R.id.btn_dayin)
    Button btn_dayin;
    @BindView(R.id.ed_remark)
    EditText ed_remark;   //备注
    @BindView(R.id.out_time)
    CommonItemView out_time;

    @BindView(R.id.tv_add_info)
    TextView tv_add_info;   //总数
    @BindView(R.id.tv_nums)
    TextView tv_nums;   //总数

    TimePickerDialog mDialogYearMonthDay;
    private int type = 0;


    private CommonPopupList mCustomerPopup, mGropPopup,mOrderPopup,mDriverPopup,mDeliveryTimePopup,mNumberPopup;;
    private List<CustomerBean.DataBean> mCustomerList = new ArrayList<>();
    private List<BranchListByCustomer.DataBean> mGropList = new ArrayList<>();
    private List<OrderListBean.DataBean> mOrderList = new ArrayList<>();
    private List<DriverListBean.DataBean> mDriverList = new ArrayList<>();
    private List<String> mDeliveryTimeList = new ArrayList<>();

    private String customerId = "",branchId="",order_id="",driverId = "",deliveryTime="";;
    private OutGoodsAdapter mCheckListAdapter;
    private ArrayList<OutGoodsBean> list = new ArrayList<>();
    BranchCodeList.DataBean branchCodeBean;

    private String branchCode = "";//分行代码
    private PrintOrderOutBean printOrderOutBean;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_out_goods_hk;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        mTitleBar.leftExit(this);
        initView();
        InitRecyclerView();
        mDeliveryTimeList = Arrays.asList(getActivity().getResources().getStringArray(R.array.week));

        mDeliveryTimePopup.setData(mDeliveryTimeList);
        btn_dayin.setVisibility(View.GONE);
        // getHotel();

    }


    @OnClick({R.id.drop_customer, R.id.drop_group,R.id.drop_driver, R.id.drop_order,R.id.btn_goods,R.id.drop_delivery_time, R.id.start_time,
            R.id.end_time, R.id.drop_number,R.id.btn_dayin,R.id.btn_orderno,R.id.btn_data,R.id.out_time,R.id.btn_nums})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.drop_customer:
                mCustomerPopup.showAsDropDown(view);
                break;
            case R.id.drop_group:
                mGropPopup.showAsDropDown(view);
                break;
            case R.id.drop_order:
                mOrderPopup.showAsDropDown(view);
                break;
            case R.id.drop_driver:
                mDriverPopup.showAsDropDown(view);
                break;
            case R.id.drop_delivery_time:
                mDeliveryTimePopup.showAsDropDown(view);
                break;
            case R.id.btn_goods:
                checkQuery();
                break;
            case R.id.start_time:
                type = 1;
                mDialogYearMonthDay.show(getSupportFragmentManager(), "year_month_day");
                break;
            case R.id.end_time:
                type = 2;
                mDialogYearMonthDay.show(getSupportFragmentManager(), "year_month_day");
                break;
            case R.id.out_time:
                type = 3;
                mDialogYearMonthDay.show(getSupportFragmentManager(), "year_month_day");
                break;
            case R.id.drop_number:
                startActivityForResult(new Intent(getActivity(), NumberActivity.class),2001);
                break;
            case R.id.btn_dayin:
                finishActivity();
                Intent mIntent = new Intent(getActivity(), OrderDetalisHkActivity.class);
                mIntent.putExtra("data", printOrderOutBean);
                startActivityForResult(mIntent, 2002);
                break;
            case R.id.btn_data:
                getInOrderDetailList(order_id);
                break;
            case R.id.btn_orderno:

                Intent intent = new Intent(getActivity(), OrderNoOutGoodsActivity.class);
                String start = startTime.getContentText();
                if (TextUtils.isEmpty(start)|| start.contains("請") || start.contains("時間")){
                    start = "";
                }
                String end = endTime.getContentText();
                if (end.contains("請") || start.contains("時間")){
                    end = "";
                }
                String state = "";

                state = "in";

                OrderNoInfoBean orderNoInfoBean = new OrderNoInfoBean(branchId,customerId,start,end,state);
                intent.putExtra("datas",orderNoInfoBean);
                startActivityForResult(intent,2002);
                break;
            case R.id.btn_nums:
                int aa = 0;
                for (int i = 0;i < list.size();i++){
                    OutGoodsBean goodsBean = list.get(i);
                    aa = goodsBean.quantityCount+aa;
                }
                tv_nums.setText(aa+"");
                break;
        }
    }

    private void initView() {
        mDriverPopup = CommonPopupList.newBuilder(this)
                .setWidthEquals(dropDriver)
                .setOnSelectItemListener(new CommonPopupList.OnSelectItemListener() {
                    @Override
                    public void onSelectItem(CommonPopupList popup, String item, int position) {
                        popup.dismiss();
                        customerId = "";
                        tvCustomer.setText(getString(R.string.order_1));
                        mCustomerList.clear();
                        tvGroup.setText(getString(R.string.order_2));
                        branchId = "";
                        mGropList.clear();
                        tvDriver.setText(item);
                        if (mDriverList != null) {
                            driverId = mDriverList.get(position).getDriverCode();
                            getCustomerList(UserHelper.get().getUserid(),driverId);
                        }

                    }
                })
                .build();

        mCustomerPopup = CommonPopupList.newBuilder(this)
                .setWidthEquals(dropCustomer)
                .setOnSelectItemListener(new CommonPopupList.OnSelectItemListener() {
                    @Override
                    public void onSelectItem(CommonPopupList popup, String item, int position) {
                        popup.dismiss();
                        tvCustomer.setText(item);
                        btn_dayin.setVisibility(View.GONE);
                        btn_goods.setVisibility(View.VISIBLE);
                        if (mCustomerList != null) {
                            // getOffice(mHospitalList.get(position).id);
                            customerId = String.valueOf(mCustomerList.get(position).getId());
                            getBranchListByCustomer(customerId);
                        }

                    }
                })
                .build();

        mGropPopup = CommonPopupList.newBuilder(this)
                .setWidthEquals(dropGroup)
                .setOnSelectItemListener(new CommonPopupList.OnSelectItemListener() {
                    @Override
                    public void onSelectItem(CommonPopupList popup, String item, int position) {
                        popup.dismiss();
                        tvGroup.setText(item);
                        if (mGropList != null) {
                            branchId = String.valueOf(mGropList.get(position).getId());
                            branchCode = mGropList.get(position).getBranchCode();
                            getOrder();

                        }

                    }
                })
                .build();
        mOrderPopup = CommonPopupList.newBuilder(this)
                .setWidthEquals(dropOrder)
                .setOnSelectItemListener(new CommonPopupList.OnSelectItemListener() {
                    @Override
                    public void onSelectItem(CommonPopupList popup, String item, int position) {
                        popup.dismiss();
                        tvOrder.setText(item);
                        btn_dayin.setVisibility(View.GONE);
                        btn_goods.setVisibility(View.VISIBLE);
                        if (mOrderList != null) {
                            order_id = String.valueOf(mOrderList.get(position).getId());
                            getInOrderDetailList(order_id);
                        }

                    }
                })
                .build();
        mDeliveryTimePopup = CommonPopupList.newBuilder(this)
                .setWidthEquals(dropDeliveryTime)
                .setOnSelectItemListener(new CommonPopupList.OnSelectItemListener() {
                    @Override
                    public void onSelectItem(CommonPopupList popup, String item, int position) {
                        popup.dismiss();
                        customerId = "";
                        tvCustomer.setText(getString(R.string.order_1));
                        mCustomerList.clear();
                        tvGroup.setText(getString(R.string.order_2));
                        branchId = "";
                        mGropList.clear();

                        List<String> datas = new ArrayList<>();
                        mCustomerPopup.setData(datas);

                        tvDeliveryTime.setText(item);
                        if (mDeliveryTimeList != null) {
                            deliveryTime = mDeliveryTimeList.get(position);
                            getCustomerList(UserHelper.get().getUserid(),driverId);
                        }

                    }
                })
                .build();

        mNumberPopup = CommonPopupList.newBuilder(this)
                .setWidthEquals(dropNumber)
                .setOnSelectItemListener(new CommonPopupList.OnSelectItemListener() {
                    @Override
                    public void onSelectItem(CommonPopupList popup, String item, int position) {
                        popup.dismiss();

                    }
                })
                .build();


        mDialogYearMonthDay = new TimePickerDialog.Builder()
                .setType(Type.YEAR_MONTH_DAY)
                .setCallBack(this)
                .build();

    }

    private void InitRecyclerView() {
        mCheckListAdapter = new OutGoodsAdapter();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        RecyclerViewUtil.setDefaultDivider(mRecyclerView, linearLayoutManager);
        mRecyclerView.setAdapter(mCheckListAdapter);
        mCheckListAdapter.setOnItemClickListener(new OutGoodsAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, AddGoodsBean data, int position) {

            }
        });
        getDriverList();
        getCustomerList(UserHelper.get().getUserid(),driverId);
    }

    private void getCustomerList(String userid,String driverCode) {
        list.clear();
        mCheckListAdapter.setNewData(list);
        MainApi.getInstance().getApi( KillerApi.class)
                .getCustomer(userid,driverCode,deliveryTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new MyObserve<CustomerBean>() {
                    @Override
                    public void onNetError(Throwable e) {
                        showOneToast(getString(R.string.order_34));
                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CustomerBean customerBean) {
                        List<String> datas = new ArrayList<>();
                        mCustomerList = customerBean.getData();
                        if (customerBean.getData()!= null && customerBean.getData().size() == 0){
                            ToastUtil.show(getActivity(),getString(R.string.order_57));
                        }
                        for (CustomerBean.DataBean bean : customerBean.getData()) {
                            datas.add(bean.getName());
                        }
                        mCustomerPopup.setData(datas);
                    }
                });
    }

    private void getBranchListByCustomer(String customerId) {
        tvGroup.setText(getString(R.string.order_2));
        branchId = "";
        list.clear();
        mCheckListAdapter.setNewData(list);
        MainApi.getInstance().getApi( KillerApi.class)
                .getBranchListByCustomer(UserHelper.get().getUserid(),customerId,driverId,deliveryTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new MyObserve<BranchListByCustomer>() {
                    @Override
                    public void onNetError(Throwable e) {
                        showOneToast(getString(R.string.order_34));
                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BranchListByCustomer branchListByCustomer) {
                        List<String> datas = new ArrayList<>();
                        mGropList = branchListByCustomer.getData();
                        if (branchListByCustomer.getData()!= null && branchListByCustomer.getData().size() == 0){
                            ToastUtil.show(getActivity(),getString(R.string.order_57));
                        }
                        for (BranchListByCustomer.DataBean bean : branchListByCustomer.getData()) {
                            datas.add(bean.getBranchName());
                        }
                        mGropPopup.setData(datas);
                    }
                });
    }

    private void getOrder() {
        list.clear();
        mCheckListAdapter.setNewData(list);
        tvOrder.setText(getString(R.string.order_3));
        order_id = "";
        String start = startTime.getContentText();
        if (TextUtils.isEmpty(start)|| start.contains("請") || start.contains("時間")){
            start = "";
        }
        String end = endTime.getContentText();
        if (end.contains("請") || start.contains("時間")){
            end = "";
        }


        MainApi.getInstance().getApi( KillerApi.class)
                .getInOrderList(branchId,UserHelper.get().getUserid(),customerId,start,end)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new MyObserve<OrderListBean>() {
                    @Override
                    public void onNetError(Throwable e) {
                        showOneToast(getString(R.string.order_34));
                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(OrderListBean orderListBean) {
                        List<String> datas = new ArrayList<>();
                        mOrderList.clear();
                        if (orderListBean.getData()!= null && orderListBean.getData().size() == 0){
                            ToastUtil.show(getActivity(),getString(R.string.order_57));
                        }
                        for (OrderListBean.DataBean bean : orderListBean.getData()) {
                            if (bean.getOutFlag().equals("0")) {
                                datas.add(bean.getOrderNo());
                                mOrderList.add(bean);
                            }
                        }
                        mOrderPopup.setData(datas);
                    }
                });
    }
    private void getDriverList() {

        MainApi.getInstance().getApi( KillerApi.class)
                .getDriverList(UserHelper.get().getUserid())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new MyObserve<DriverListBean>() {
                    @Override
                    public void onNetError(Throwable e) {
                        showOneToast(getString(R.string.order_34));
                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(DriverListBean customerBean) {
                        List<String> datas = new ArrayList<>();
                        mDriverList = customerBean.getData();
                        if (customerBean.getData()!= null && customerBean.getData().size() == 0){
                            ToastUtil.show(getActivity(),getString(R.string.order_57));
                        }
                        for (DriverListBean.DataBean bean : customerBean.getData()) {
                            datas.add(bean.getDriverName());
                        }
                        mDriverPopup.setData(datas);
                    }
                });
    }
    private void getInOrderDetailList(String order_id) {
        if (TextUtils.isEmpty(order_id) ){
            showOneToast(getString(R.string.order_65));
            return;
        }
        printOrderOutBean = new PrintOrderOutBean();
        MainApi.getInstance().getApi( KillerApi.class)
                .getInOrderDetailList(UserHelper.get().getUserid(),order_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new MyObserve<OrderDetailListBean>() {
                    @Override
                    public void onNetError(Throwable e) {
                        showOneToast(getString(R.string.order_34));
                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(OrderDetailListBean orderListBean) {
                        LogPlus.e("orderListBean="+orderListBean.toString());
                        list.clear();
                        if (orderListBean.getData()!= null && orderListBean.getData().size() == 0){
                            ToastUtil.show(getActivity(),getString(R.string.order_57));
                        }
                        String info = "";
                        for (int i = 0;i < orderListBean.getData().size();i++){
                            OrderDetailListBean.DataBean data = orderListBean.getData().get(i);
                            OutGoodsBean bean  = new OutGoodsBean(branchId,customerId,data.getDebtCount(),data.getNum(),String.valueOf(data.getProductListDto().getId()),
                                    0,0,data.getProductListDto().getProductName());
                            list.add(bean);
                            printOrderOutBean.address = data.getCustomerBranchDto().address;
                            printOrderOutBean.branchContactNumber = data.getCustomerBranchDto().branchContactNumber;
                            printOrderOutBean.inboundDate = data.inboundDate;
                            info = data.getOrderInDto().getRemark();
                        }
                        mCheckListAdapter.setNewData(list);
                        tv_add_info.setText(info);

                    }
                });
    }



    private void checkQuery() {
        if (printOrderOutBean == null){
            return;
        }
        List<AddOrderOutBean.OrderOutDetailsBean> orderInDetailList = new ArrayList<>();
        AddOrderOutBean addOrderInBean = new AddOrderOutBean();
        int totalnums = 0;

        for (int i = 0;i < list.size();i++){
            OutGoodsBean goodsBean = list.get(i);
            if (goodsBean.quantityCount < 0 ){
                showOneToast(getString(R.string.order_43));
                return;
            }
        }
        int nums = 0;
        for (int i = 0;i < list.size();i++){
            OutGoodsBean goodsBean = list.get(i);
            totalnums = goodsBean.quantityCount- goodsBean.supplementCount;
            AddOrderOutBean.OrderOutDetailsBean bean = new AddOrderOutBean.OrderOutDetailsBean(goodsBean.branchId,UserHelper.get().getUserid(),
                    goodsBean.customerId,goodsBean.debtCount,Integer.parseInt(order_id),goodsBean.nums,goodsBean.productId,
                    totalnums,goodsBean.supplementCount,UserHelper.get().getUserid());
            if (goodsBean.supplementCount > goodsBean.debtCount ){
                showOneToast(getString(R.string.order_29));
                return;
            }
            if (goodsBean.quantityCount > (goodsBean.debtCount+goodsBean.nums) ){
                showOneToast(getString(R.string.order_36));
                return;
            }
//            if (goodsBean.quantityCount <= 0){
//                showOneToast(getString(R.string.order_35));
//                return;
//            }
            nums = nums+goodsBean.quantityCount;
            orderInDetailList.add(bean);
        }
        if (nums == 0){
            showOneToast(getString(R.string.order_76));
            return;
        }
        addOrderInBean.setOrderOutDetails(orderInDetailList);

        ////////////出货单数据传递到打印界面///////////////////
        List<PrintOrderOutBean.OrderOutDetailsBean> printlList = new ArrayList<>();

        for (int i = 0;i < list.size();i++){
            OutGoodsBean goodsBean = list.get(i);
            PrintOrderOutBean.OrderOutDetailsBean bean = new PrintOrderOutBean.OrderOutDetailsBean(goodsBean.debtCount,goodsBean.nums,goodsBean.quantityCount, goodsBean.supplementCount,goodsBean.productName);
            printlList.add(bean);
        }
        printOrderOutBean.setOrderOutDetails(printlList);
        printOrderOutBean.customerName = tvCustomer.getText().toString();
        printOrderOutBean.code = branchCode;
        String remark = ed_remark.getText().toString();
        if (TextUtils.isEmpty(remark)){
            remark = "";
        }
        printOrderOutBean.remark = remark;
        addOrderInBean.remark = remark;
        String outTimeText = out_time.getContentText();
        if (TextUtils.isEmpty(outTimeText)|| outTimeText.contains("日期")){
            outTimeText = "";
        }
        addOrderInBean.outboundDate = outTimeText;
        printOrderOutBean.outboundDate = outTimeText;
        LogPlus.e("addOrderInBean="+addOrderInBean.toString());
        showWaitingDialog("请等待",true);

        MainApi.getInstance().getApi( KillerApi.class)
                .addOrderOut(addOrderInBean)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(ActivityEvent.DESTROY))
                .subscribe(new MyObserve<OrderBean>() {
                    @Override
                    public void onNetError(Throwable e) {
                        LogPlus.e("e.getMessage()"+e.getLocalizedMessage());
                        showOneToast(getString(R.string.order_34));
                    }

                    @Override
                    public void onSubscribe(Disposable d) {
                        LogPlus.e("onSubscribe");
                    }

                    @Override
                    public void onNext(OrderBean orderBean) {
                        LogPlus.e("onNext");
                        dismissWaitingDialog();
                        showOneToast(getString(R.string.order_16));
                        btn_dayin.setVisibility(View.VISIBLE);
                        btn_goods.setVisibility(View.GONE);
                        printOrderOutBean.order_No = orderBean.getData();

                        tvOrder.setText(getString(R.string.order_3));
                        order_id = "";
                        mOrderList.clear();
                        List<String> datas = new ArrayList<>();
                        mOrderPopup.setData(datas);
//                        finishActivity();
                    }
                });
    }
    @Override
    public void onDateSet(TimePickerDialog timePickerView, long millseconds) {
        if (type == 1) {
            startTime.setContent(TimeFormats.formatDateTime1(timePickerView.getCurrentMillSeconds()));
        } if (type == 2) {
            endTime.setContent(TimeFormats.formatDateTime1(timePickerView.getCurrentMillSeconds()));
        }else {
            out_time.setContent(TimeFormats.formatDateTime1(timePickerView.getCurrentMillSeconds()));
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == 4 && data != null) {
            branchCodeBean = (BranchCodeList.DataBean) data.getSerializableExtra("data");
            if (branchCodeBean != null) {
                tvNumber.setText(branchCodeBean.getBranchCode());
                tvCustomer.setText(branchCodeBean.getCustomerName());
                customerId = branchCodeBean.getCustomerId()+"";
                tvGroup.setText(branchCodeBean.getBranchName());
                branchId = branchCodeBean.getId()+"";
                branchCode = branchCodeBean.getBranchCode();
                getOrder();
            }
        }
        if (resultCode == 5 && data != null) {

            OrderListBean.DataBean changOrderNo = (OrderListBean.DataBean) data.getSerializableExtra("data");
            if (changOrderNo != null) {
                tvOrder.setText(changOrderNo.orderNo);
                order_id = changOrderNo.id + "";
                branchCode = changOrderNo.branchCode;
                if (!TextUtils.isEmpty(changOrderNo.getCustomerId())) {
                    customerId = changOrderNo.getCustomerId() + "";
                }
                if (!TextUtils.isEmpty(changOrderNo.customerName)) {
                    tvCustomer.setText(changOrderNo.customerName);
                }
                if (!TextUtils.isEmpty(changOrderNo.branchName)) {
                    tvGroup.setText(changOrderNo.branchName);
                }
                if (!TextUtils.isEmpty(changOrderNo.branchId)) {
                    branchId = changOrderNo.branchId+"";
                }

                getInOrderDetailList(order_id);
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
